package com.putong35.common.httprequest.volleyadaptee;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;

import java.util.HashMap;
import java.util.Map;

class NormalPostRequest extends Request<String> {
    private Map<String, String> mMap;
    private Response.Listener<String> mListener;
    private Map<String, String> mHeaderParams;

    public NormalPostRequest(String url, Map<String, String> map, Map<String, String> headerParams, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(Request.Method.POST, url, errorListener);
        mHeaderParams = headerParams;
        mListener = listener;
        mMap = map;
    }

    //mMap是已经按照前面的方式,设置了参数的实例
    @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        return mMap;
    }


    @Override
    protected Response<String> parseNetworkResponse(NetworkResponse response) {
        return ResponseHelper.parseNetworkResponse2String(response);
    }


    @Override
    public Map<String, String> getHeaders() {
        HashMap<String, String> headers = new HashMap<String, String>();
        headers.put("Accept", "application/json");
        headers.put("Content-Type", "application/json; charset=UTF-8");
        if (mHeaderParams != null && mHeaderParams.size() > 0) {
            headers.putAll(mHeaderParams);
        }
        return headers;
    }


    @Override
    protected void deliverResponse(String response) {
        mListener.onResponse(response);
    }
}


